<template>
	<view class="background purchase-list">
		<!-- <view class="position_t flex aic jcsb">
			<image @click="back()" src="@/static/back.png" mode=""></image>
		</view> -->
		<scroll-view class="purchase-body" scroll-y="true" @scrolltolower="scrolltolower" @scrolltoupper="scrolltoupper"
			show-scrollbar="false">
			<view class="" style="padding: 0 12px;">
				<view class="">
					<view class="position_content">
						<ComponyHearder :data="ComponyHearderData" />
					</view>
					<view class="position_content_main">
						<view class="flex" style="flex-wrap: wrap;">
							<p class="fontz fontc3d fonts12">工作时间：{{workTimeStart}}</p>
						</view>
						<view class="flex componyheader_cntent_right_text aic">
							<!-- <text class="fontz fonts12 gray">福利待遇：</text> -->
							<text class="Inventory_btn_"
								v-for="item in string_arrFun(welfare)">{{dictFuns(item,'welfare_treatment')}}</text>
						</view>
						<view class="line" style="margin-top: 16px;"></view>
						<p class="fontz fontc3d fontw700 fonts12" style="margin: 10px 0;">公司简介</p>
						<p class="fontz fonts12 color2" v-text="componyInfo"></p>
						<p class="fontz fontc3d fontw700 fonts12" style="margin: 10px 0;">主营产品与业务</p>
						<p class="fontz fonts12 color2" v-text="mainProducts">
						</p>
						<p class="fontz fontc3d fontw700 fonts12" style="margin: 10px 0;">公司相册</p>
						<el-carousel height="180px">
							<el-carousel-item v-for="(item, index) in adPicFiles" :key="index">
								<img class="index_top_bg_imgs" style="height: 180px;width: 100%;"
									:src="item.url" alt="">
							</el-carousel-item>
						</el-carousel>
						<p class="fontz fontc3d fontw700 fonts12" style="margin: 10px 0;">公司地址</p>
						<view v-if="address!=''">
							<BaiduMap :data="address"/>
						</view>
					</view>
					<view class="index_header">
						<view class="index_header_top flex">
							<text @click="headerClick(item,index)" v-for="(item,index) in HeadersData" :key="index"
								:class="indexHeaderValue==index?'indexBack1 fontw700 fonts14':'indexBack2 fonts14'">{{item.label}}{{item.number>0?`(${item.number})`:``}}</text>
						</view>
					</view>
					<view class="" v-if="indexHeaderValue==0" @click="detail(item)" v-for="item in list_p">
						<Inventory :data="item" />
					</view>
					<view class="" v-if="indexHeaderValue==1" @click="details(item)" v-for="item in list_g">
						<view class="flex jcsb index_header">
							<text class="fonts12">{{item.announcementTitle}}</text><text
								class="fonts12">{{item.createTime}}</text>
						</view>
					</view>

				</view>
				<view class="">
					<p class="more" v-if="onMore">没有更多了~</p>
					<p class="more" v-if="loading">加载中...</p>
				</view>
			</view>

		</scroll-view>

	</view>
</template>

<script>
	import {
		getselect,
		getlist,
		homeConfiguration,
		companyAnnouncement
	} from "@/api/index"
	import {
		dictFun
	} from "@/util/dictionary"
	import BaiduMap from "../../components/BaiduMaps.vue"
	import Inventory from "../../components/Inventory.vue"
	import ComponyHearder from "../../components/ComponyHeader.vue"
	export default {
		components: {
			Inventory,
			ComponyHearder,
			BaiduMap
		},
		data() {
			return {
				address:"",
				onMore: false,
				loading: false,
				totalBool: true,
				indexHeaderValue: 0,
				HeadersData: [{
					label: "在招职位",
					number: "0",
					id: 0
				}, {
					label: "公示公告",
					number: "0",
					id: 1
				}],
				personData: {},
				ComponyHearderData: {
					img: "",
					title: "",
					companyType: "",
					companySize: "",
					companyIndustry: "",
					address: "",
					bool: ""
				},
				componyInfo: "",
				workTimeStart: "",
				mainProducts: "",
				welfare: [],
				adPicFiles: [],
				form_p: {
					pageNum: 1,
					pageSize: 10,
					tenantId: ""
				}, //在招职位
				list_p: [],
				list_g: [],
				form_g: {
					pageNum: 1,
					pageSize: 10,
					tenantId: ""
				},

			};
		},
		onLoad(options) {
			this.personData = JSON.parse(options.data)
			this.info()
		},
		onPullDownRefresh() {
			if (this.indexHeaderValue == 0) {
				this.form_p.pageNum = 1
				this.getlistApi(this.form_p)
			}

		},
		methods: {
			dictFuns(value, res) {
				return dictFun(value, res)
			},
			string_arrFun(res) {
				console.log(res);
				let arrs = res ? res.split(",") : []
				return arrs
			},
			info() { //初始化数据
				console.log("数据集：", this.personData);
				let tenantVo = this.personData.tenantVo
				console.log("---------------------",tenantVo);
				this.ComponyHearderData = {
					img: tenantVo.companyLogoUrl,
					title: tenantVo.companyName,
					companyType: tenantVo.companyType,
					companySize: tenantVo.companySize,
					companyIndustry: tenantVo.companyIndustry,
					mainProducts: tenantVo.mainProducts,
					address: tenantVo.address,
					workTimeStart: tenantVo.workTimeStart,
					bool: 1
				}
				this.address=tenantVo.address
				console.log("-----------------------------",this.address);
				this.componyInfo = tenantVo.intro
				this.mainProducts = tenantVo.mainProducts
				this.workTimeStart = tenantVo.workTimeStart
				this.welfare = tenantVo.welfare
				this.adPicFiles = tenantVo.adPicFiles ? tenantVo.adPicFiles : []
				this.form_p.tenantId = this.personData.tenantId
				this.form_g.tenantId = this.personData.tenantId
				this.form_p.pageNum = 1
				this.form_g.pageNum = 1
				this.getlistApi(this.form_p)
				this.getlistApi_g(this.form_g)
			},
			back() {
				uni.navigateBack(-1)
			},
			detail(item) {
				uni.navigateTo({
					url: "/pages/index/position/position?data=" + JSON.stringify(item)
				})
			},
			details(item) {
				uni.navigateTo({
					url: "/pages/index/compony/componyDetail/componyDetail?data=" + JSON.stringify(item)
				})
			},
			headerClick(item, index) {
				this.form_g.pageNum = 1
				this.form_p.pageNum = 1
				this.indexHeaderValue = index
				if (this.indexHeaderValue == 0) {
					this.getlistApi(this.form_g)
				} else {
					this.getlistApi_g(this.form_g)
				}


			},
			getlistApi(params) { //在招职位
				this.loading = true
				getlist(params).then((res) => {
					this.loading = false
					this.HeadersData[0].number = res.total
					if (this.form_p.pageNum == 1) {
						this.list_p = res.rows
					} else {
						this.list_p = [...this.list_p, ...res.rows]
					}
					console.log(this.list_p.length, res.total);
					if (this.list_p.length == res.total) {
						this.onMore = true
						this.totalBool = false
						setTimeout(() => {
							this.onMore = false
						}, 2000)
					} else {
						this.totalBool = true
					}
					uni.stopPullDownRefresh()
				})
			},
			getlistApi_g(params) { //公示公告
				this.loading = true
				companyAnnouncement(params).then((res) => {
					this.loading = false
					console.log(res);
					if (this.form_g.pageNum == 1) {
						this.list_g = res.rows
					} else {
						this.list_g = [...this.list_g, ...res.rows]
					}
					this.HeadersData[1].number = res.total
					console.log(this.list_g.length, res.total);
					if (this.list_g.length == res.total) {
						this.onMore = true
						this.totalBool = false
						setTimeout(() => {
							this.onMore = false
						}, 2000)
					} else {
						this.totalBool = true
					}
					uni.stopPullDownRefresh()
				})
			},


			scrolltolower(event) {
				if (this.indexHeaderValue == 0) {
					if (!this.totalBool) {
						this.onMore = true
						this.totalBool = false
						setTimeout(() => {
							this.onMore = false
						}, 2000)
						return
					}
					this.form_p.pageNum++;
					this.getlistApi(this.form_p)
				} else {
					if (!this.totalBool) {
						this.onMore = true
						this.totalBool = false
						setTimeout(() => {
							this.onMore = false
						}, 2000)
						return
					}
					this.form_g.pageNum++;
					this.getlistApi(this.form_g)
				}

			},

			scroll(e) {
				// 重新设置pulldown
				this.setPullDown(e.detail.scrollTop < 10)
			},

			scrolltoupper() {

			},
		}
	}
</script>

<style lang="scss" scoped>
	.Inventory_btn_ {
		padding: 3px 10px;
		color: #2F6CBC;
		border: 1px solid #2F6CBC;
		background: #EFF3F7;
		border-radius: 10px 10px 10px 10px;
		font-size: 10px;
		margin-right: 10px;
		margin-top: 5px;
	}

	.more {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 30px;
		width: 100%;
		font-size: 14px;
		color: #3D3D3D;
	}

	.purchase-list {
		background-color: #f5f5f5;
		height: calc(100vh - 50px);
		overflow: hidden;

		.purchase-body {
			height: calc(100vh - 50px);
			overflow-y: auto;

			&::-webkit-scrollbar {
				display: none;
				/*隐藏滚动轴*/
			}
		}
	}

	.position_t {
		z-index: 1;
		width: 100%;
		position: fixed;
		height: 44px;

		image {
			width: 30px;
			height: 30px;
		}

		.position_t_right {
			text {
				margin-right: 20px;
				color: #2F6CBC;
			}

			image {
				width: 18px;
				height: 17px;
			}
		}

	}

	// .position_content{
	// 	padding-top: 44px;
	// }
	.color2 {
		color: #606266;
	}

	.indexBack1 {
		color: #2F6CBC;
	}

	.indexBack2 {
		color: #3D3D3D;
	}

	.index_header {
		margin-top: 8px;
		padding: 14px;
		background: #FFFFFF;
		border-radius: 0px 0px 0px 0px;
		opacity: 1;

		.index_header_top {
			text {
				margin-right: 24px;

			}
		}

		.index_header_bottom {
			margin-top: 13px;
		}
	}

	.position_content_main {
		.line {
			border-top: 1px dashed #979797;
			margin-bottom: 16px;
		}

		// margin-top: 10px;
		padding: 13px 15px;
		background: #FFFFFF;
	}

	.content_s {
		height: calc(100vh - 64px);
		margin-top: 44px;
		overflow: hidden;
		padding-bottom: 20px;

		&::-webkit-scrollbar {
			display: none;
			/*隐藏滚动轴*/
		}

	}
</style>
